package com.ayf.payment.game.api.service.impl;

import com.ayf.payment.game.api.entity.TemplateChannel;
import com.ayf.payment.game.api.exception.ParameterException;
import com.ayf.payment.game.api.mapper.TemplateChannelMapper;
import com.ayf.payment.game.api.service.TemplateChannelService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TemplateChannelServiceImpl implements TemplateChannelService {

    @Resource
    private TemplateChannelMapper templateChannelMapper;

    @Override
    public boolean insertChannels(List<TemplateChannel> channelList) {
        if (channelList == null) {
            throw new ParameterException("渠道赠送参数不能为空");
        }
        return templateChannelMapper.insertChannels(channelList) > 0;
    }

    @Override
    public List<TemplateChannel> selectAllByTemplateId(String templateId) {
        TemplateChannel channel = checkParameter(templateId);
        return templateChannelMapper.select(channel);
    }

    private TemplateChannel checkParameter(String templateId) {
        if (StringUtils.isBlank(templateId)) {
            throw new ParameterException("模板id不能为空");
        }
        TemplateChannel channel = new TemplateChannel();
        channel.setTemplateId(templateId);
        return channel;
    }

    @Override
    public boolean delChannelByTemId(String templateId) {
        TemplateChannel channel = checkParameter(templateId);
        return templateChannelMapper.delete(channel) > 0;
    }
}


